package com.lazily.map_;


import java.util.HashMap;
import java.util.Map;

/**
 * @Author: GZQ
 * @date: 2025/6/1 16:58
 * @description: Map 接口的常用方法
 * @version: 1.0
 */

@SuppressWarnings({"all"})
public class MapMethod {
	// 程序入口
	public static void main(String[] args) {
		// 	演示map接口的常用方法

		Map map = new HashMap();
		map.put("邓超", new Book("", 100));// OK
		map.put("邓超", "孙俪");// 替换-> 一会分析源码
		map.put("王宝强", "马蓉");// OK
		map.put("宋喆", "马蓉");// OK
		map.put("刘令博", null);// OK
		map.put(null, "刘亦菲");// OK
		map.put("鹿晗", "关晓彤");// OK
		map.put("lazily", null);

		System.out.println("map = " + map);

		// 	remove: 根据键删除映射关系
		map.remove(null);
		System.out.println("map = " + map);

		// 	get: 根据键获取值
		Object val = map.get("鹿晗");
		System.out.println("val = " + val);

		// 	size: 获取元素个数
		System.out.println("k-v=" + map.size());

		// 	isEmpty: 判断个数是否为0
		System.out.println("k-v=" + map.isEmpty()); // false

		// 	clear: 清除
		map.clear();
		System.out.println("map = " + map);

		// 	containsKey: 查找键是否存在
		System.out.println(map.containsKey("lazily"));

	}

}

@SuppressWarnings({"all"})
class Book {
	private String name;
	private int price;

	public Book(String name, int price) {
		this.name = name;
		this.price = price;
	}
}